package newcoder;

import java.util.*;

/**
 * @Author 肖地洋
 * @Date 2022/7/15 13:54
 */


public class NC148 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int T = in.nextInt();
        Map<String,String> map = new HashMap();
        for(int t=0;t<T;t++){
            map.put(in.next(),in.next());
        }


        int N = in.nextInt();

        for(int n =0;n<N;n++){
            String str = in.nextLine();
            String[] strarr = str.split("s+");
            System.out.println();
        }
        System.out.println();
    }


}


